<template>
<!--试题审核对话框  -->
  <div class='container'>
       <el-form 
       :model="ruleForm" 
       :rules="rules" 
       ref="ruleForm"
       >
        <el-radio-group v-model="ruleForm.chkState">
          <el-radio :label="1">通过</el-radio>
          <el-radio :label="2">不通过</el-radio>
        </el-radio-group>
       <el-form-item  prop="chkRemarks" class="input">
          <el-input 
          type="textarea" 
          v-model="ruleForm.chkRemarks" 
          :rows="2"
         placeholder="请输入内容"></el-input>
       </el-form-item>
       </el-form>
        <span slot="footer" class="dialog-footer">
          <div></div>
         <div>
           <el-button @click="$emit('close')">取 消</el-button>
           <el-button type="primary" @click="submitOnclick">确 定</el-button>
         </div>
      </span>
  </div>
</template>

<script>
// 导入提交审核API
import { choiceCheck } from '@/api/hmmm/questions.js'
export default {
  name: 'QuestionsCheck',
  data () {
    return {
      ruleForm: {
        chkState: parseInt(this.newData.chkState),
       // 原因
       chkRemarks: ''
      },
      // 验证规则
      rules: {
         chkRemarks: [
            { required: true, message: '请填写审核意见', trigger: 'blur' }
          ]
      } 
    }
  },
  props: {
    auditVisible: {
      type: Boolean,
      required: true
    },
    newData: {
      type: Object,
      required: true
    }
  },
  methods: {
    // 提交
    submitOnclick () {
      console.log(this.newData)
      const datas = {
        id: this.newData.id,
        chkState: parseInt(this.ruleForm.chkState),
        chkRemarks: this.ruleForm.chkRemarks
      }
         this.$refs.ruleForm.validate(async (valid) => {
           if (!valid) return 
           try {
             await choiceCheck(datas)
             this.$emit('updata-chkState', this.ruleForm.chkState)
             this.$emit('close')
           } catch (err) {
              this.$message('提交失败')
           }
    })
  }
}
}
</script>
<style scoped lang='scss'>
.container {
  .dialog-footer {
    display: flex;
    margin-top: 20px;
    justify-content: space-between;
  }
  .input {
    margin: 20px 0 20px 0;
  }
}
</style>
